//
//  CGWService+GWServiceIPPort.m
//  etionCBLogic
//
//  Created by wjxfhxy on 1/26/14.
//  Copyright (c) 2014 GuangZhouXuanWu. All rights reserved.
//

#import "GWService+GWServiceIPPort.h"

#import "ProtocolBase.h"

#import "ProtocolTransformType.h"

#import "XLGProtocolRequestAddress.h"

#import "HTTPProtocolBase.h"

@implementation CGWService (GWServiceIPPort)

-(XLGProtocolRequestAddress*)getGWServiceProtocol:(CProtocolBase*)protocol
{
    switch((int)protocol.transformType)
    {
        case EProtocolTransformTypeHTTPSREST:
        case EProtocolTransformTypeHTTPSRESTFORFILE:
        {
            if([XLGProtocolRequestAddress protocolRequestAddress] != NULL)
            {
                return [XLGProtocolRequestAddress protocolRequestAddress](@"");
            }
            
            NSString *httpAddress = [XLGContext context].HTTPaddress;
            if(protocol.transformType == EProtocolTransformTypeHTTPSRESTFORFILE)
                httpAddress =[XLGContext context].fileHTTPaddress[2];
            
            return [[[XLGProtocolRequestAddress alloc]initWithWebsite:httpAddress]autorelease_mm];
            
            break;
        }
        case EProtocolTransformTypeSocketStream:
        {
            if([XLGProtocolRequestAddress protocolRequestAddress] != NULL)
            {
                return [XLGProtocolRequestAddress protocolRequestAddress]([@(protocol.commandID) stringValue]);
            }
            
            break;
        }
    }
    return nil;
}

@end
